package freightCalculator;

public class Result {

    float p;
    float s;
    float w;
    public Result(float p, float s, float w){
        this.p=p;
        this.s=s;
        this.w=w;
    }
    public float getDiscountRate() {
        int range;
        if (s < 250) {
            range = 1;
        } else if (s < 500) {
            range = 2;
        } else if (s < 1000) {
            range = 3;
        } else if (s < 2000) {
            range = 4;
        } else if (s < 3000) {
            range = 5;
        } else {
            range = 6;
        }

        return switch (range) {
            case 1 -> 0;
            case 2 -> 0.02f;
            case 3 -> 0.05f;
            case 4 -> 0.08f;
            case 5 -> 0.10f;
            case 6 -> 0.15f;
            default -> 0; // Default case for unexpected values
        };
    }
    public double calculateFreight(){
        double basicFreight = p * s * w; // 基本运费
        double discountRate = getDiscountRate(); // 根据路程获取折扣率
        return basicFreight * (1 - discountRate);
    }

}
